package edu.mit.media.fv.components
{
	import flash.display.*;
	import flash.events.MouseEvent;
	import flash.filters.*;
	import flash.text.*;
	
	public class FVCheckBox extends Sprite
	{
		private var _label:TextField;
		private var _radio:Sprite;
		private var _width:int;
		private var _height:int;
		private var _foreground:uint;
		private var _bevelUp:BevelFilter = new BevelFilter(
			4, 45, 0xFFFFFF, 1, 0, 1, 4, 4, 1, 1);
		
		private var _selected:Boolean = false;
		
		public function FVCheckBox(x:int, y:int, width:int, height:int, text:String){
			super();
			this.x = x;
			this.y = y;
			
			this._foreground = 0xFFFFFF;
			this._width = width;
			this._height = height;
			
			var format:TextFormat = new TextFormat();
			format.align = TextFormatAlign.CENTER;
			format.bold = true;
			format.font = "Arial";
			format.size = height*.8;
			format.color = _foreground;
			this._label = new TextField();
			this._label.defaultTextFormat = format;
			this._label.type = TextFieldType.DYNAMIC;
			this._label.selectable = false;
			this._label.text = text;
			this._label.width = width-height;
			this._label.height = height;
			this._label.text = text;
			this._label.x = height;
			
			this._radio = new Sprite();
			
			this.addChild(this._radio);
			this.addChild(this._label);
			
			this.addEventListener(MouseEvent.CLICK, radioSelected);
			
			this.reform();
			this._radio.filters = [this._bevelUp];
		}
		public function get text():String{
			return this._label.text;
		}
		public function set selected(selected:Boolean):void{
			this._selected = selected;
			this.reform();
		}
		public function get selected():Boolean{
			return this._selected;
		}
		private function radioSelected(event:MouseEvent):void{
			this.selected = !this.selected;
		}
		private function reform():void{
			if(this.selected){
				this._radio.graphics.clear();
				this._radio.graphics.lineStyle(3,0x000000,0.7,true);
				this._radio.graphics.beginFill(0xEEEEEE, 1.0);
				this._radio.graphics.drawRoundRect(0,0,_height, _height, 3, 3);
				this._radio.graphics.endFill();
				this._radio.graphics.beginFill(0x000000, 1.0);
				this._radio.graphics.drawRoundRect(10,10,_height-20, _height-20, 3, 3);
				this._radio.graphics.endFill();
			
			}else{
				this._radio.graphics.clear();
				this._radio.graphics.lineStyle(3,0x000000,0.7,true);
				this._radio.graphics.beginFill(0xEEEEEE, 0.0);
				this._radio.graphics.drawRoundRect(0,0,_height, _height, 3, 3);
				this._radio.graphics.endFill();
			}
			
		}

	}
}